package com.cskaoyan.service.vxbrand;

import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.MarketBrandExample;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.vxaddressvo.VXBrandListVO;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.cskaoyan.service.vxaddress.VXAddressService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 创建日期: 2022/05/08 20:17
 *
 * @author shuyang
 */
@Service
public class VXBrandServiceImpl implements VXBrandService {
    @Autowired
    MarketBrandMapper marketBrandMapper;

    @Override
    public VXBrandListVO queryBrandListInVX(BaseParam baseParam) {
        Integer page = baseParam.getPage();
        Integer limit = baseParam.getLimit();
        PageHelper.startPage(page, limit);
        MarketBrandExample marketBrandExample = new MarketBrandExample();
        MarketBrandExample.Criteria criteria = marketBrandExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(marketBrandExample);
        PageInfo<MarketBrand> marketBrandPageInfo = new PageInfo<>(marketBrands);
        int pages = marketBrandPageInfo.getPages();
        int total = (int) marketBrandPageInfo.getTotal();
        return new VXBrandListVO(total, pages, limit, page, marketBrands);
    }

    @Override
    public MarketBrand queryBrandDetail(Integer id) {
        MarketBrand marketBrand = marketBrandMapper.selectByPrimaryKey(id);
        return marketBrand;
    }
}
